/**
 *  Copyright 2002 Quaseem
 *  Copyright 2004 Migisan
 *  Copyright 2008 Oest
 *
 *  This file is part of the aochat package.
 *
 *  The aochat package is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  The aochat package is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with the aochat package; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

package sk.sigp.aobot.client.types;

import java.io.*;

import sk.sigp.aobot.client.types.general.AbstractType;

public class GroupId extends AbstractType {
	protected long mydata;

	public GroupId() {
		mydata = 0;
	}

	public GroupId(long i) {
		mydata = i;
	}

	public GroupId(DataInputStream input) throws IOException {
		byte[] bytes = new byte[5];
		input.readFully(bytes);
		mydata = ((bytes[0] & 0xFFL) << 32) + ((bytes[1] & 0xFFL) << 24)
				+ ((bytes[2] & 0xFFL) << 16) + ((bytes[3] & 0xFFL) << 8)
				+ (bytes[4] & 0xFFL);
	}

	public long getLongData() {
		return mydata;
	}

	public byte[] getRaw() {
		byte[] ret = new byte[5];
		ret[0] = (byte) ((mydata >> 32) & 0xFF);
		ret[1] = (byte) ((mydata >> 24) & 0xFF);
		ret[2] = (byte) ((mydata >> 16) & 0xFF);
		ret[3] = (byte) ((mydata >> 8) & 0xFF);
		ret[4] = (byte) ((mydata >> 0) & 0xFF);
		return ret;
	}

	public int size() {
		return 5;
	}

	public String toString() {
		return super.toString() + "( " + mydata + " )";
	}
	
	public int hashCode() {
		return (int) mydata;
	}

	public boolean equals(Object gid) {
		if (!(gid instanceof GroupId)) return false;
		if (gid != null)
			return mydata == ((GroupId)gid).mydata;
		return false;
	}
}
